package com.ls.httpstudy.http;

import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Deprecated
public class WebClientUtil {
    //创建WenClient实例
    private WebClient webClient;

    public WebClientUtil() {
//        webClient = WebClient.create();
        WebClient.Builder builder = WebClient.builder().exchangeStrategies(ExchangeStrategies.builder().codecs(configurer ->
                configurer.defaultCodecs()
                        .maxInMemorySize(10 * 1024 * 1024)).build()
        );
        webClient = builder.build();
    }

    public WebClientUtil(WebClient webClient) {
        this.webClient = webClient;

    }

    public String doGet(String httpUrl) {
        Mono<String> mono = webClient
                .method(HttpMethod.GET)
                .uri(httpUrl)
                //获取响应结果
                .retrieve()
                //将结果转换为指定类型
                .bodyToMono(String.class);

        return mono.block();
    }

    public String doPost() {
        webClient.method(HttpMethod.POST);
        return "";
    }

    public static void main(String[] args) {

    }
}
